/**
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PANDA_ASSEMBLER_EXTENSIONS_REGISTER_EXTENSIONS_H
#define PANDA_ASSEMBLER_EXTENSIONS_REGISTER_EXTENSIONS_H

#include "extensions/extensions.h"

% Common::plugins.each_value do |plugin_opts|
%   next unless plugin_opts["Metadatas"]
%   plugin_opts["Metadatas"].each_value do |new_class_opts|
// NOLINTNEXTLINE(readability-duplicate-include)
#include "<%= new_class_opts["header_path"] %>"
%   end
% end

namespace panda::pandasm::extensions {

// NOLINTBEGIN(misc-definitions-in-headers)

%["RecordMetadata", "FieldMetadata", "FunctionMetadata", "ParamMetadata"].each do |metadata|
/* static */
std::unique_ptr<<%= metadata %>> MetadataExtension::Create<%= metadata %>([[maybe_unused]] panda::panda_file::SourceLang lang)
{
%   Common::plugins.each_value do |plugin_opts|
%     next unless plugin_opts["Metadatas"]
%     next unless plugin_opts["Metadatas"][metadata]
    if (lang == <%= plugin_opts["lang_enum"] %>) {
        return std::make_unique <<%= plugin_opts["Metadatas"][metadata]["new_class_name"] %>>();
    }
%   end

    return std::make_unique<<%= metadata %>>();
}

% end

// NOLINTEND(misc-definitions-in-headers)

}  // namespace panda::pandasm::extensions

#endif  // PANDA_ASSEMBLER_EXTENSIONS_REGISTER_EXTENSIONS_H
